//
//  Animation2RoundedCornerViewController.m
//  UITest
//
//  Created by wp w on 12-6-6.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "Animation2RoundedCornerViewController.h"
#import "roundedCornerView.h"

@implementation Animation2RoundedCornerViewController

CGFloat radiansForDegrees(CGFloat degrees) 
{
	return (M_PI * degrees / 180.0);
}

- (void)viewDidLoad {
	
    [super viewDidLoad];
	
	CGPoint frameCenter = self.view.center;
	float width  = 50;
	float height = 50;
	
	CGRect viewFrame = CGRectMake(frameCenter.x-width, frameCenter.y-height,width*2, height*2);
	roundedCornerView *myView = [[roundedCornerView alloc] initWithFrame:viewFrame];
	
	myView.backgroundColor = [UIColor blueColor];
	[[self view] addSubview:myView];
	
	CGRect subViewFrame = CGRectInset(myView.bounds,width/2,height/2);
	roundedCornerView *mySubview = [[roundedCornerView alloc] initWithFrame:subViewFrame];
	mySubview.backgroundColor = [UIColor yellowColor];
	[myView addSubview:mySubview];	
	
    
    //此时已经有了一个小的view
    //动画开始，执行1秒钟。动画结束时要求变为一个大的view。在动画的过程应用了缩放和旋转变换
    //动画提交
	[UIView beginAnimations:nil context:NULL];
	
	[UIView setAnimationDuration:1.0];
	
	CGAffineTransform scale = CGAffineTransformMakeScale(2.0,2.0);
	CGAffineTransform rotate = CGAffineTransformMakeRotation(radiansForDegrees(180));
	CGAffineTransform myTransform = CGAffineTransformConcat(scale,rotate);
	myView.transform = myTransform;
	
	[UIView commitAnimations];
	
	[mySubview release];
	[myView release];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
